package com.atguigu.lease.common.handle;

import com.atguigu.lease.model.enums.ItemTypeEnum;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

//@Component
public class StringToItemTypeEnumConverter implements Converter<String, ItemTypeEnum> {
    @Override
    public ItemTypeEnum convert(String source) {
        ItemTypeEnum[] itemTypeEnums = ItemTypeEnum.class.getEnumConstants();
        for (ItemTypeEnum itemTypeEnum : itemTypeEnums) {
            if (itemTypeEnum.name().equals(Integer.parseInt(source))) {
                return itemTypeEnum;
            }
        }
        throw new RuntimeException("type:"+source+" not supported");
    }
}
